<?php

namespace App\Repository\Repositories;

use App\Repository\Models\Attributes;
use App\Repository\Repositories\Interfaces\AttributesRepository;

/**
 * Class AttributesRepositoryEloquent.
 *
 * @package namespace App\Repository\Repositories;
 */
class AttributesRepositoryEloquent extends BaseRepository implements AttributesRepository
{
    /**
     * 搜索
     * @var array
     */
    protected $fieldSearchable = [
        'name'=> 'like',
        'created_at'=>'between',
        'is_sku',
        'id'=> 'in',
    ];

    /**
     * 可关联查询的字段
     */
    public $withAllow = [
        'attrValues'=> ['attribute_id', 'value','id'],
    ];

    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return Attributes::class;
    }
    
    public function getAttrs($ids)
    {
        return $this->with(['attrValues' => function($query){
            $query->select(['attribute_id','value','id']);
        }])->findWhereIn('id',$ids);
    }

    
}
